package com.buba.other.controller;


import com.buba.other.service.impl.DivisionTypeServiceImpl;
import com.buba.pojo.other.DivisionType;
import com.buba.pojoVo.DivisionTypeVo;
import com.buba.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 科室类型表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-06-09
 */
@Slf4j
@RestController
@RequestMapping("/other/division-type")
public class DivisionTypeController {

    @Autowired
    private DivisionTypeServiceImpl divisionTypeService;

    public DivisionTypeController() {
    }

    @GetMapping({"/selectDepartment/{id}"})
    @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
    public R selectDepartment(@PathVariable("id") Integer id) {
        log.info("id==" + id);
        List<DivisionType> department = this.divisionTypeService.selectDepartment(id);
        log.info("department==" + department);
        return department != null ? R.ok().data("department", department) : R.error();
    }

    @GetMapping({"/getDepartments/{HospitalId}"})
    public R getDepartments(@PathVariable("HospitalId") Integer HospitalId) {
        if (HospitalId == null) {
            HospitalId = 1;
        }

        List<DivisionTypeVo> list = this.divisionTypeService.getDepartments1(HospitalId);
        return list != null ? R.ok().data("list", list) : R.error();
    }

    @GetMapping({"/getDepartment/{DepartmentId1}/{DepartmentId2}"})
    public R getDepartment(@PathVariable("DepartmentId1") Integer DepartmentId1,@PathVariable("DepartmentId2") Integer DepartmentId2) {

        DivisionType divisionType1 = divisionTypeService.getDepartment(DepartmentId1);
        DivisionType divisionType2 = divisionTypeService.getDepartment(DepartmentId2);
        if(divisionType1 != null || divisionType2 != null){
            return R.ok().data("divisionType1",divisionType1).data("divisionType2",divisionType2);
        }else{
            return R.error();
        }
    }

}

